package com.wt.冒泡插入选择排序;

public class bubbling {
    public static void main(String[] args) {
        Integer[] arr = {1, 7, 5, 6, 4, 2, 8, 9, 3, 10, 13, 12};
        int temp;
        System.out.println("冒泡排序：");
        for (int i = 1; i < arr.length; i++) {
            for (int j = 0; j < arr.length - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "：");
        }

        System.out.println("\n插入排序：");
        for (int i = 0; i < arr.length; i++) {
            int min = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[min]) {
                    min = j;
                }
            }
            if (min != i) {
                temp = arr[min];
                arr[min] = arr[i];
                arr[i] = temp;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "：");
        }
    }
}
